package com.xtecher.app.user;

import com.xtecher.app.Config;
import com.xtecher.app.okhttp.IRequestManager;
import com.xtecher.app.okhttp.OnLoadListener;
import com.xtecher.app.okhttp.RequestFactory;

/**
 * Created by Luhao on 2017/2/24.
 */
public class UserPresenter implements UserContact.Presenter {

    private final IRequestManager manager;
    private UserContact.View mView;

    public UserPresenter(UserContact.View view) {
        mView = view;
        manager = RequestFactory.getRequestManager();
    }

    @Override
    public void start() throws Exception {

    }


    @Override
    public void getUserInfo(String url) {
        if (mView != null) {
            mView.showLoading("");
        }
        manager.get(Config.GETUSERINFO + url, new OnLoadListener() {
            @Override
            public void onSuccess(Object o) {
                if (mView != null) {
                    mView.setData(o, 0);
                    mView.hideLoading();
                }
            }

            @Override
            public void onFailed(String msg) {
                if (mView != null) {
                    mView.hideLoading();
                    mView.onError(msg);
                    mView.showMessage(msg);
                }
            }
        });
    }
}
